package org.shj.netty.chartper12;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket;
import io.netty.util.CharsetUtil;

public class ChineseProverbClientHandler extends SimpleChannelInboundHandler<DatagramPacket>{
	
	
	public ChineseProverbClientHandler(){
		
	}
	
	protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception{
		String res = msg.content().toString(CharsetUtil.UTF_8);
		if(res.startsWith("谚语查询结果:")){
			System.out.println(res);
			ctx.close();
		}
	}
	
	
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause){
		cause.printStackTrace();
		ctx.close();
	}
}
